
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>所有虎客刷题系统-学生</title>
    <script src="../js/jquery-3.4.1.min.js"></script>
    <style>
        table th{
            background-color: lightcyan;
        }
        table td{
            background-color: lightgrey;
        }
    </style>
</head>
<body>
<%--<p>
    欢迎管理员 <%=request.getParameter("login")%>
</p>--%>
  <h1>所有用户</h1>
  <a href="toAdd">新用户注册</a>
    <p>${msg}</p>
<p align="center">
    <form action="search" id="searchForm">
    <input type="hidden" name="pageNo" value="${p.page}"/>
      <input type="search" name="realname" value="${realname}" placeholder="请输入用户名"/>
      <input type="search" name="loginname" value="${loginname}" placeholder="请输入登录名"/>
      <input type="search" name="phone" value="${phone}" placeholder="请输入手机名"/>
    <input type="submit" value="搜索" id="search"/>
    </form>
</p>
  <table border="1" cellpadding="0" cellspacing="0" align="center">
      <tr>
          <th>编号</th>
          <th>登录名</th>
          <th>姓名</th>
          <th>手机号</th>
          <th>大头照</th>
          <th>操作</th>
      </tr>
    <c:forEach items="${p.data}" var="u">
      <tr>
          <td>${u.id}</td>
          <td>${u.loginname}</td>
          <td>${u.realname}</td>
          <td>${u.phone}</td>
          <td>
              <c:if test="${not empty u.headpic}">
              <img src="../${u.headpic}" height="40px" width="60px" />
              </c:if></td>
          <td><a href="del-${u.id}" onclick="return confirm('真的要删除${u.realname}?')"  >删除</a>
           <%--   <a href="toUpdate?id=${u.id}">修改</a>
              <a href="del?id=${u.id}">重置密码</a>--%>
              <a href="to-${u.id}">修改</a>
              <a >重置密码</a>
          </td>

      </tr>
    </c:forEach>
  </table>
<p align="center" id="pager">
    <a href="users.jsp?pageNo=1" data-id="1">首页</a>

    <c:if test="${p.page>1}">
    <a href="users.jsp?pageNo=${p.page-1}" data-id="${p.page-1}">上一页</a>
    </c:if>
    <input type="number" min="1" value="${p.page}" name="pageNo" style="width: 50px"/>/${p.pageNums}<button type="button" id="goto">直达</button>

    <c:if test="${p.page<p.pageNums}">
    <a href="users.jsp?pageNo=${p.page+1}" data-id="${p.page+1}">下一页</a>
    </c:if>
    <a href="users.jsp?pageNo=${p.pageNums}" data-id="${p.pageNums}">尾页</a>
</p>
<script>
    // function goTo(t) {
    //     window.location.href="users.jsp?pageNo="+t.previousElementSibling.value;
    // }
    $(function () {
        $("#search").click(function () {
            $("#searchForm input[name=pageNo]").val(1);
        });
        $("#goto").click(function () {
            $("#searchForm input[name=pageNo]").val($(this).prev().val());
            $("#searchForm").submit();
        });
       $("#pager a").click(function () {
           //this是表示当前元素，是Dom元素
           let n=$(this).data("id");
           //$(this).prop("data-id");
           //alert(n);
           $("#searchForm input[name=pageNo]").val(n);
           $("#searchForm").submit();
           return false;
       });
    });
</script>
</body>
</html>
